# 生成平衡二叉搜索树

class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right
        # pass

class Solution:

    # 递归的方式
    def sortedArrayToBST(self, nums):

        if not nums:
            return None
        
        m = len(nums) // 2
        left = self.sortedArrayToBST(nums[0: m])
        right = self.sortedArrayToBST(nums[m + 1:])

        return TreeNode(nums[m], left, right)


